//
//  WSOrderDetailTableViewProxy.m
//  FD
//
//  Created by xiaofang wang on 2019/1/8.
//  Copyright © 2019年 ZhiYuan Network. All rights reserved.
//  抽取tableView 代理方法

#import "WSOrderDetailTableViewProxy.h"

//view
#import "WSOrderDetailCell.h"
#import "WSOrderDetailSectionHeaderView.h"

//model
#import "WSOrderSectionModel.h"
#import "WSOrderCellModel.h"

// cell高度自适应
#import "UITableViewCell+FSAutoCountHeight.h"

@implementation WSOrderDetailTableViewProxy


#pragma mark - 代理1 UITableViewDataSource,
//最上边有一个餐品信息,对数据源做手脚是最方便的的
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    WSOrderSectionModel *sectionModel = self.dataArray[section];
    NSArray *rowArr = sectionModel.rowArr;
    
    return rowArr.count; //0 或者 1个
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WSOrderDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WSOrderDetailCell"];
    
    //给cell赋值
    WSOrderSectionModel *sectionModel = self.dataArray[indexPath.section];

    WSOrderCellModel *model = sectionModel.rowArr[indexPath.row];
    cell.model = model;
    
    return cell;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    WSOrderDetailSectionHeaderView *sectionHV = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"WSOrderDetailSectionHeaderView"];

    //赋值
    WSOrderSectionModel *sectionModel = self.dataArray[section];
    sectionHV.sectionModel = sectionModel;
    
    return sectionHV;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

//    WSOrderSectionModel *sectionModel = self.dataArray[indexPath.section];


    //cell高度自适应
//    WSOrderCellModel *cellModel = sectionModel.rowArr[indexPath.row];
//   CGFloat height = [WSOrderDetailCell FSCellHeightForTableView:tableView indexPath:indexPath cacheKey:cellModel.identifier cellContentViewWidth:0 bottomOffset:0]; //不好使
    
    CGFloat height = [WSOrderDetailCell FSCellHeightForTableView:tableView indexPath:indexPath cellContentViewWidth:0 bottomOffset:0]; //✅
 
    return height;
}


#pragma mark - 取消group 模式多余边距
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *fv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.1)];
    return fv;

//    return nil; //2019-2-18 在iOS10.3的真机下这个会设置无效。
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}
@end
